package com.ciccwm.msg.service;

import com.ciccwm.core.exception.ValidationException;
import com.ciccwm.msg.api.DubboMsgService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.shenyu.client.apidocs.annotations.ApiDoc;
import org.apache.shenyu.client.apidocs.annotations.ApiModule;
import org.apache.shenyu.client.dubbo.common.annotation.ShenyuDubboClient;
import org.apache.shenyu.common.utils.GsonUtils;

/**
 * 消息服务
 */
@Slf4j
@DubboService
@ApiModule(value = "dubboMsgService")
public class DubboMsgServiceImpl implements DubboMsgService {

    @Override
    @ShenyuDubboClient("/sendMsg")
    @ApiDoc(desc = "sendMsg")
    public String sendMsg(final String msg) {
        log.info(GsonUtils.getInstance().toJson(RpcContext.getServerAttachment().getObjectAttachments()));
        if (msg == null || msg.isEmpty()) {
            throw new ValidationException("msg is empty");
        }
        return RpcContext.getServerAttachment().getAttachment("traceId");
    }
}
